<?php

declare(strict_types=1);

namespace app\index\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class Article extends Model
{
    //
    protected $name = 'campus_article';

    protected function category()
    {
        return $this->belongsTo(Category::class, 'category_id');
    }


    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }

    // 获取器：用户昵称
    public function getUserNicknameAttr($value, $data)
    {
        return User::where('id', $data['user_id'])->value('nickname');
    }

    // 获取器：用户头像
    public function getUserAvatarAttr($value, $data)
    {
        return User::where('id', $data['user_id'])->value('avatar');
    }
}
